package com.ruoyi.business.controller;

import com.ruoyi.business.domain.ProjectDetailTemplate;
import com.ruoyi.business.service.ProjectDetailTemplateService;
import com.ruoyi.business.domain.vo.ProjectDetailTemplateVO;
import com.ruoyi.common.annotation.CheckUnique;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.PageDomain;
import com.ruoyi.common.core.domain.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;

/**
 * 视图接口 : 个人项目模板
 * @Author  : ljq
 * @Created : 2025/10/8
 */
@RestController
@RequestMapping("/business/projectDetailTemplate")
public class ProjectDetailTemplateController extends BaseController {

    @Resource
    private ProjectDetailTemplateService service;

    private static final String BASE_AUTH = "business:projectDetailTemplate";
    private static final String LOG_TITLE = "个人项目模板#个人项目模板表 -- ProjectDetailTemplateController";


    /**
     * 列表
     */
    @PreAuthorize("@ss.hasPermi('"+BASE_AUTH+":list')")
    @GetMapping("/list")
    public TableDataInfo list(ProjectDetailTemplate entity, PageDomain pageDomain) {
        return TableDataInfo.build(
                service.listByCondition(entity, pageDomain)
        );
    }


    /**
     * 获取
     */
    @PreAuthorize("@ss.hasPermi('"+BASE_AUTH+":query')")
    @GetMapping("/{id}")
    public AjaxResult query(@PathVariable Long id) {
        ProjectDetailTemplate one = service.getById(id);
        return null == one ?  AjaxResult.noContent() : AjaxResult.success(one);
    }

    /**
     * 获取多项
     */
    @PreAuthorize("@ss.hasPermi('"+BASE_AUTH+":query')")
    @GetMapping("/batch/{ids}")
    public AjaxResult queryBatch(@PathVariable List<Long> ids) {
        List<ProjectDetailTemplateVO> list = service.listByIds(ids);
        return list.isEmpty() ?  AjaxResult.noContent() : AjaxResult.success(list);
    }


     /**
      * 新增
      */
     @PreAuthorize("@ss.hasPermi('"+BASE_AUTH+":add')")
     @Log(title = LOG_TITLE, businessType = BusinessType.INSERT)
     @CheckUnique(table = "t_project_detail_template", where = "xxxx", message = "xxxx")
     @PostMapping
     public AjaxResult add(@Validated @RequestBody ProjectDetailTemplate entity) {
         return toAjax(service.save(entity));
     }

     /**
      * 新增
      */
     @PreAuthorize("@ss.hasPermi('"+BASE_AUTH+":add')")
     @Log(title = LOG_TITLE, businessType = BusinessType.INSERT)
//     @CheckUnique(table = "t_project_detail_template", where = "xxxx", message = "xxxx")
     @PostMapping("batch")
     public AjaxResult addBatch(@Validated @RequestBody List<ProjectDetailTemplate> entityList) {
         return toAjax(service.saveBatch (entityList));
     }


     /**
      * 修改
      */
     @PreAuthorize("@ss.hasPermi('"+BASE_AUTH+":edit')")
     @Log(title = LOG_TITLE, businessType = BusinessType.UPDATE)
     @CheckUnique(excludeId = "id", table = "t_project_detail_template", where = "xxxx", message = "xxxx")
     @PutMapping
     public AjaxResult edit(@Validated @RequestBody ProjectDetailTemplate entity) {
         return toAjax(service.updateById(entity));
     }


     /**
      * 删除
      */
     @PreAuthorize("@ss.hasPermi('"+BASE_AUTH+":remove')")
     @Log(title = LOG_TITLE, businessType = BusinessType.DELETE)
     @DeleteMapping("/{ids}")
     public AjaxResult remove(@PathVariable Long[] ids) {
         return toAjax(service.removeByIds(Arrays.asList(ids)));
     }


}